//
//  ForgetPassWordViewController.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/7/26.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ForgetPassWordViewController.h"
#import "GetPhoneNumber.h"

#define Margin 8

@interface ForgetPassWordViewController ()
{
    UITextField *phoneNumberTextField;
    UITextField *againNewPasswordTextField;
    UITextField *newPasswordTextField;
    UITextField *yzmTextField;
}

@end

@implementation ForgetPassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setNavUI];
    
    [self setUpUI];
}

- (void)setNavUI {
 
    self.navigationController.navigationBar.backgroundColor = DEFAULT_COLOR;
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"jiantou"] highImage:[UIImage imageNamed:@"jiantou"] target:self action:@selector(backToPre) forControlEvents:UIControlEventTouchUpInside title:nil];
    self.navigationItem.leftBarButtonItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    customLab.textAlignment = NSTextAlignmentCenter;
    [customLab setText:@"忘记密码"];
    customLab.font = [UIFont boldSystemFontOfSize:18];
    self.navigationItem.titleView = customLab;
    
}

- (void)backToPre {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setUpUI {
    UILabel *inputPhone = [[UILabel alloc] init];
    inputPhone.text = @"请输入手机号:";
    inputPhone.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:inputPhone];
    
    [inputPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).with.offset(Margin * 2);
        make.top.equalTo(self.view.mas_top).with.offset(HEIGHT /7);
        make.width.mas_equalTo(WIDTH * 0.3);
        make.height.mas_equalTo(25);
    }];
    
    phoneNumberTextField = [[UITextField alloc] init];
    phoneNumberTextField.borderStyle = UITextBorderStyleRoundedRect;
    phoneNumberTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self.view addSubview:phoneNumberTextField];
    
    [phoneNumberTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(inputPhone.mas_right).with.offset(Margin * 2);
        make.top.equalTo(inputPhone.mas_top);
        make.width.mas_equalTo(WIDTH * 0.5);
        make.height.mas_equalTo(inputPhone.mas_height);
    }];
    
    UILabel *yzmLabel = [[UILabel alloc] init];
    yzmLabel.text = @"请输入验证码:";
    yzmLabel.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:yzmLabel];
    
    [yzmLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(inputPhone.mas_bottom).with.offset(Margin * 3);
        make.left.equalTo(inputPhone.mas_left);
        make.width.mas_equalTo(inputPhone.mas_width);
        make.height.mas_equalTo(inputPhone.mas_height);
    }];
    
    yzmTextField = [[UITextField alloc] init];
    yzmTextField.borderStyle = UITextBorderStyleRoundedRect;
    yzmTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self.view addSubview:yzmTextField];
    
    [yzmTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneNumberTextField.mas_left);
        make.top.equalTo(yzmLabel.mas_top);
        make.width.mas_equalTo(WIDTH * 0.25);
        make.height.mas_equalTo(yzmLabel.mas_height);
    }];

    UIButton *yzmButton = [[UIButton alloc] init];
    yzmButton.layer.cornerRadius = 4;
    yzmButton.layer.masksToBounds = YES;
    [yzmButton setBackgroundColor:DEFAULT_COLOR];
    [yzmButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    [yzmButton addTarget:self action:@selector(didClickYZMButton:) forControlEvents:UIControlEventTouchUpInside];
    [yzmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    yzmButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:yzmButton];
    
    [yzmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(phoneNumberTextField.mas_right);
        make.centerY.equalTo(yzmTextField.mas_centerY);
        make.width.mas_equalTo(WIDTH * 0.25 - Margin);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *newPasswordLabel = [[UILabel alloc] init];
    newPasswordLabel.text = @"请输入新密码:";
    [self.view addSubview:newPasswordLabel];
    
    [newPasswordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(yzmLabel.mas_bottom).with.offset(Margin * 3);
        make.left.equalTo(yzmLabel.mas_left);
        make.width.mas_equalTo(yzmLabel.mas_width);
        make.height.mas_equalTo(yzmLabel.mas_height);
    }];
    
    newPasswordTextField = [[UITextField alloc] init];
    newPasswordTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:newPasswordTextField];
    
    [newPasswordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneNumberTextField.mas_left);
        make.top.equalTo(newPasswordLabel.mas_top);
        make.width.mas_equalTo(phoneNumberTextField.mas_width);
        make.height.mas_equalTo(yzmLabel.mas_height);
    }];
    
    UILabel *againPasswordLabel = [[UILabel alloc] init];
    againPasswordLabel.text = @"重新输入密码:";
    [self.view addSubview:againPasswordLabel];
    
    [againPasswordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(newPasswordLabel.mas_left);
        make.top.equalTo(newPasswordLabel.mas_bottom).with.offset(Margin * 3);
        make.width.mas_equalTo(newPasswordLabel.mas_width);
        make.height.mas_equalTo(newPasswordLabel.mas_height);
    }];

    againNewPasswordTextField = [[UITextField alloc] init];
    againNewPasswordTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:againNewPasswordTextField];
    
    [againNewPasswordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneNumberTextField.mas_left);
        make.top.equalTo(againPasswordLabel.mas_top);
        make.width.mas_equalTo(phoneNumberTextField.mas_width);
        make.height.mas_equalTo(yzmLabel.mas_height);
    }];
    
    UIButton *confirmButton = [[UIButton alloc] init];
    confirmButton.layer.cornerRadius = 5;
    confirmButton.layer.masksToBounds = YES;
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton setBackgroundColor: DEFAULT_COLOR];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(didClickConfirmButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmButton];
    
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(againNewPasswordTextField.mas_bottom).with.offset(HEIGHT * 0.1 - Margin);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(WIDTH * 0.5);
        make.height.mas_equalTo(30);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  验证码
 */
- (void)didClickYZMButton:(UIButton *)button {
    [self clearTextFieldResign];
    
    [[GetPhoneNumber SharedGetPhoneNumber] getFotgetPhoneVerifyNumber:button andPhoneNumber:phoneNumberTextField.text andView:self.view];
}

/**
 *  确定按钮
 */
- (void)didClickConfirmButton {
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self clearTextFieldResign];
}

- (void)clearTextFieldResign {
    [phoneNumberTextField resignFirstResponder];
    [againNewPasswordTextField resignFirstResponder];
    [newPasswordTextField resignFirstResponder];
    [yzmTextField resignFirstResponder];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
